import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20180509.DeleteSimilarityLibraryRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

public class SimilarityLibraryDeleteSample extends BaseSample{

    public static void main(String[] args) throws Exception{
        //请替换成你自己的accessKeyId、accessKeySecret
        IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint(getEndPointName(), regionId, "Green", getDomain());

        IAcsClient client = new DefaultAcsClient(profile);
        DeleteSimilarityLibraryRequest deleteSimilarityLibraryRequest = new DeleteSimilarityLibraryRequest();
        deleteSimilarityLibraryRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式
        deleteSimilarityLibraryRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法
        deleteSimilarityLibraryRequest.setEncoding("utf-8");
        deleteSimilarityLibraryRequest.setProtocol(ProtocolType.HTTP);
        deleteSimilarityLibraryRequest.setRegionId(regionId);
        deleteSimilarityLibraryRequest.setHttpContentType(FormatType.JSON);


        JSONObject data = new JSONObject();
        data.put("name", "test");
        deleteSimilarityLibraryRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);

        /**
         * 请务必设置超时时间
         */
        deleteSimilarityLibraryRequest.setConnectTimeout(3000);
        deleteSimilarityLibraryRequest.setReadTimeout(10000);
        try {
            HttpResponse httpResponse = client.doAction(deleteSimilarityLibraryRequest);

            if (httpResponse.isSuccess()) {
                JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                System.out.println(JSON.toJSONString(scrResponse, true));
            } else {
                System.out.println("response not success. status:" + httpResponse.getStatus());
            }
        } catch (ServerException e) {
            String errorCode = e.getErrCode();
            if(errorCode.equals("Throttling.User")){

            }
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        } catch (Exception e){
            e.printStackTrace();
        }
    }
}
